package com.esl.action.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class Checker implements Interceptor {

	private String sessionAttribute;
	private String reloginResult;
	private String exActionName;
	private String checkNamespace;

	public String getSessionAttribute() {
		return sessionAttribute;
	}

	public void setSessionAttribute(String sessionAttribute) {
		this.sessionAttribute = sessionAttribute;
	}

	public String getReloginResult() {
		return reloginResult;
	}

	public void setReloginResult(String reloginResult) {
		this.reloginResult = reloginResult;
	}

	public String getExActionName() {
		return exActionName;
	}

	public void setExActionName(String exActionName) {
		this.exActionName = exActionName;
	}

	public String getCheckNamespace() {
		return checkNamespace;
	}

	public void setCheckNamespace(String checkNamespace) {
		this.checkNamespace = checkNamespace;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 6967450338086765737L;

	@Override
	public void destroy() {

	}

	@Override
	public void init() {

	}

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		Map<String, Object> session = arg0.getInvocationContext().getSession();
		String[] exActionlist = exActionName.split(",");
		if (arg0.getProxy().getNamespace().equals(checkNamespace))
			if (!session.containsKey(sessionAttribute))
				for (String exName : exActionlist) {
					if (!arg0.getProxy().getActionName().equals(exName))
						return reloginResult;
					break;
				}

		return arg0.invoke();
	}

}
